#include "mylabel.h"
#include <QDebug>
#include <QMouseEvent>
Mylabel::Mylabel(QWidget *parent) : QLabel(parent)
{

}

void Mylabel::enterEvent(QEvent *event)
{
    qDebug() << "进入";
}

void Mylabel::mousePressEvent(QMouseEvent *event)
{
    //如果鼠标左键按下，那就打印控件的相对坐标，如果是右键就打印全局的坐标
    if(event->button() == Qt::LeftButton)
    {
        QString str = QString("当前鼠标所在的位置: x = %1 y = %2").arg(event->x()).arg(event->y());
        qDebug() << str;
    }
    if(event->button() == Qt::RightButton)
    {
        QString str = QString("相对整个屏幕的坐标: x = %1 y = %2").arg(event->globalX()).arg(event->globalY());
        qDebug() << str;
    }
}
